﻿package idv.cjcat.monica.platformer.player {
	import idv.cjcat.monica.Const;
	import idv.cjcat.monica.Ref;
	import idv.cjcat.rusher.engine.entities.Entity;
	import idv.cjcat.rusher.engine.entities.PropertyReference;
	import idv.cjcat.rusher.rendering2d.IRenderTargetComponent;
	import idv.cjcat.rusher.spatial2d.ISpatial2DComponent;
	import idv.cjcat.rusher.spatial2d.Spatial2DComponent;
	
	public class Player extends Entity {
		
		private var _body:PlayerSpatialComponent;
		public function get body():PlayerSpatialComponent { return _body; }
		
		private var _controller:PlayerController;
		public function get controller():PlayerController { return _controller; }
		
		private var _frontCameraTarget:ISpatial2DComponent;
		public function get frontCameraTarget():ISpatial2DComponent { return _frontCameraTarget; }
		
		private var _backCameraTarget:ISpatial2DComponent;
		public function get backCameraTarget():ISpatial2DComponent { return _backCameraTarget; }
		
		private var _topCameraTarget:ISpatial2DComponent;
		public function get topCameraTarget():ISpatial2DComponent { return _topCameraTarget; }
		
		private var _bottomCameraTarget:ISpatial2DComponent;
		public function get bottomCameraTarget():ISpatial2DComponent { return _bottomCameraTarget; }
		
		private var _renderTarget:PlayerRenderTarget;
		public function get renderTarget():PlayerRenderTarget { return _renderTarget; }
		
		public function Player() {
			_body = new PlayerSpatialComponent();
			_body.name = Const.SPATIAL;
			_body.awake = true;
			
			_controller = new PlayerController();
			_controller.name = Const.CONTROLLER;
			
			_frontCameraTarget = new Spatial2DComponent();
			_frontCameraTarget.name = Const.FRONT_CAMERA_TARGET;	
			
			_backCameraTarget = new Spatial2DComponent();
			_backCameraTarget.name = Const.BACK_CAMERA_TAREGT;
			
			_topCameraTarget = new Spatial2DComponent();
			_topCameraTarget.name = Const.TOP_CAMERA_TARGET;
			
			_bottomCameraTarget = new Spatial2DComponent();
			_bottomCameraTarget.name = Const.BOTTOM_CAMERA_TARGET;
			
			_renderTarget = _controller.renderTarget = new PlayerRenderTarget();
			_renderTarget.name = Const.RENDER_TARGET;
			_renderTarget.positionRef = Ref.POSITION;
			_renderTarget.scaleRef = new PropertyReference(Const.RENDER_TARGET, Const.SCALE);
			_renderTarget.zIndex = 5;
			
			addComponent(_body);
			addComponent(_renderTarget);
			addComponent(_controller);
			addComponent(_frontCameraTarget);
			addComponent(_backCameraTarget);
		}
	}
}